package com.app.reptile.utils;

/**
 * js 脚本
 */
public class JsScript {

    /**
     * 滚动脚本
     * @return
     */
    private static StringBuilder scrollScript(){
        StringBuilder builder = new StringBuilder();
        builder.append("function smoothScrollTo(xPos, yPos, duration) { ");
        builder.append("var interval = 10; ");
        builder.append("var step = (yPos - window.scrollY) / (duration / interval); ");
        builder.append("function scroll() { ");
        builder.append("window.scrollBy(0, step); ");
        builder.append("if (window.scrollY < yPos) { ");
        builder.append("setTimeout(scroll, interval); ");
        builder.append("} ");
        builder.append("} ");
        builder.append("scroll(); ");
        builder.append("} ");
        return builder;
    }

    public static String scrollBottomScript(){
        StringBuilder builder = scrollScript();
        // 平滑滚动到页面底部，耗时2000毫秒
        builder.append("window.scrollTo({top: document.body.scrollHeight,behavior: 'smooth'}); ");
        return builder.toString();
    }


    /**
     * 获取页面加载是否完成
     * @return
     */
    public static String documentStatus(){
        return "return document.readyState=='complete'";
    }




}
